package com.entity;

import com.DeleteObjectsRequestTypeConverter;
import com.amazonaws.services.s3.model.DeleteObjectsRequest;
import picocli.CommandLine.Command;
import picocli.CommandLine.Option;

import java.io.File;
import java.util.List;
import java.util.concurrent.Callable;

/**
 * 文档
 * https://picocli.info/#_add_as_external_dependency
 */
@Command(name = "aws", header = "Version 2.0", requiredOptionMarker = '*',
        abbreviateSynopsis = true, sortOptions = false)
public class PackCmd implements Callable<Integer> {

    private Callable<Integer> callable;

    @Option(names = "-help", usageHelp = true, description = "显示帮助并退出")
    boolean help;

    @Option(names = {"-cls", "-clear"}, description = "清理 CloudFront 缓存")
    public boolean clear;

    /** 打包类型 1 打包上传 2 创建桶 3 更改权限 */
    @Option(names = {"-t", "-type"}, description = "打包类型 1 打包上传 2 创建桶 3 更改权限")
    public int type;

    /** 在公共账户信息文件中的别名 */
    @Option(names = {"-n", "-name"}, description = "账户信息文件中的别名")
    public String profile;

    /** 登录钥匙 */
    @Option(names = {"id", "accessKeyId"}, description = "账号id")
    public String accessKeyId;

    /** 登录钥匙密码 */
    @Option(names = {"psd", "accessKeySecret"}, description = "密码")
    public String accessKeySecret;

    /** 桶名字 */
    @Option(names = {"bname", "bucketName"}, description = "桶名字")
    public String bucketName;

    /** 上传服务器的根路径 */
    @Option(names = {"rp", "rootPath"}, description = "上传服务器的根路径")
    public String rootPath;

    /** 父路径 */
    @Option(names = {"p", "parent"}, description = "父路径")
    public String parentPath;

    /** 上传文件配置表 */
    @Option(names = {"-r", "-read"}, description = "上传文件配置表")
    public String uploadFileConfig;

    /** 需要打包到指定目录的文件 */
    @Option(names = {"-p", "-pack"}, description = "需要打包到指定目录的文件")
    public String uploadFilePackFile;

    /** 要上传的文件 */
    @Option(names = {"add", "addFile"}, description = "要上传的文件", split = ",")
    public List<File> uploadFileList;

    /** 要删除的文件 */
    @Option(names = {"rm", "deleteFile"}, description = "要删除的文件", split = ",", converter = DeleteObjectsRequestTypeConverter.class)
    public List<DeleteObjectsRequest.KeyVersion> deleteFileList;

    /** 要被清理服务器的id */
    @Option(names = {"dbId", "distributionId"}, description = "要被清理服务器的id,如果设置了此值，那么更新的时候不在去服务器获取桶id，推荐手动设置这样可以快速清理缓存")
    public String distributionId;

    public PackCmd(Callable<Integer> callable) {
        this.callable = callable;
    }

    @Override
    public Integer call() throws Exception {
        if (callable != null) callable.call();
        return null;
    }

    @Override
    public String toString() {
        return "PackCmd{" +
                "help=" + help +
                ", clear=" + clear +
                ", type=" + type +
                ", userFile='" + profile + '\'' +
                ", accessKeyId='" + accessKeyId + '\'' +
                ", accessKeySecret='" + accessKeySecret + '\'' +
                ", bucketName='" + bucketName + '\'' +
                ", rootPath='" + rootPath + '\'' +
                ", parentPath='" + parentPath + '\'' +
                ", uploadFileConfig='" + uploadFileConfig + '\'' +
                ", uploadFilePackFile='" + uploadFilePackFile + '\'' +
                ", uploadFileList=" + uploadFileList +
                ", deleteFileList=" + deleteFileList +
                '}';
    }
}